#pragma once

#include "string/stringoutput.h"
#include "Core/CAbstractThread.h"
#include "testlibpilo.h"


class MyThread : public CAbstractThread
{
public:
    INT32 onRun();


    void setValue(INT32 v) { _value = v; }
    void incValue() {_value ++; }
    INT32 value() const {return _value;}

private:

    INT32   _value;

};

class MyThreadSlowTask : public CAbstractThread
{
public:
    MyThreadSlowTask()
    {
        postKilledCalled = 0;
        preKilledCalled = 0;
    }
    INT32 onRun();

    void onThreadPreKill()
    {
        if (postKilledCalled == 0) {
            preKilledCalled = 1;
        }
    }

    void onThreadPostKill()
    {
        if (preKilledCalled == 1) {
            postKilledCalled = 1;
        }
    }

    INT32 postKilledCalled;
    INT32 preKilledCalled;

    void setValue(INT32 v) { _value = v; }
    void incValue() 
    {
        usleep(200);
        _value ++;
    }
    INT32 value() const {return _value;}

private:

    INT32   _value;

};

class MyThreadQuickTask : public CAbstractThread
{
public:
    MyThreadQuickTask()
    {
        _finished = FALSE;
        postKilledCalled = FALSE;
        preKilledCalled = FALSE;
        finshed = FALSE;
    }
    INT32 onRun();
    void onThreadPreKill()
    {
        if (postKilledCalled == 0) {
            preKilledCalled = 1;
        }
    }

    void onThreadPostKill()
    {
        if (preKilledCalled == 1) {
            postKilledCalled = 1;
        }
    }

    void onFinished() 
    {
        finshed = TRUE;
    }


    void setValue(INT32 v) { _value = v; }
    void incValue() {_value ++; }
    INT32 value() const {return _value;}

    INT32 postKilledCalled;
    INT32 preKilledCalled;
    INT32 finshed;

private:

    BOOL    _finished;
    INT32   _value;

};
